import React, {Component} from 'react';
import {SafeAreaView, TouchableOpacity, TextInput, View, Text, StyleSheet, Dimensions} from 'react-native';
import StorageServer from '../../storage/Storage';
const screen = Dimensions.get('screen');
const styles = StyleSheet.create({
    box: {
        height: screen.height,
        alignItems: 'center',
        justifyContent: 'center',
        flexDirection: 'column'
    }
});
class LoginPage extends Component{
    constructor(props) {
        super(props);
        this.state = {
            value : '请输入登陆信息',
            isLogin: false
        };
        // this.props.navigation.addListener('beforeRemove', (e) =>{
        //     if(!this.state.isLogin){
        //         e.preventDefault();
        //     }
        // })
    }


    onChangeText = (v) =>{
        this.setState({
            value:v
        });
    }
    _login = () => {
        StorageServer.saveData('token', '123123').then(() => {
            this.setState({
                isLogin:true
            });
            this.props.navigation.navigate('tab');
        });

    }
    render() {
        return (
            <SafeAreaView style={styles.box}>
                <View>
                    <TextInput
                        onChangeText={text => this.onChangeText(text)}
                        style={{ height: 40, borderColor: 'gray', borderWidth: 1 }}
                        value={this.state.value}
                    />
                </View>
                <TouchableOpacity onPress={this._login}>
                    <Text>登陆</Text>
                </TouchableOpacity>
            </SafeAreaView>

        );
    }
}
export default LoginPage;
